package com.joven.shelltest.test;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Author wzj
 * @Date 2023-08-10 09:29
 **/
public class OtherTest4 {
    public static void main(String[] args) {
//        System.out.println(DigestUtils.md5Hex("hZxByokS" + "3537eb9615807c1dea2a5d4fa3c08eb5a3553f17"));
//        // 创建一个Calendar对象
//        Calendar calendar = Calendar.getInstance();
//        // 设置日期为当前日期
//        calendar.setTime(new Date());
//        // 减去一年
//        calendar.add(Calendar.YEAR, -1);
//        // 获取减去一年后的日期
//        Date newDate = calendar.getTime();
//        SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM-dd");
//        System.out.println("减去一年后的日期: " + monthFormat.format(newDate));

//        System.out.println(Thread.currentThread().getStackTrace()[1].getClassName());
//        System.out.println(OtherTest4.class.getSimpleName());

        String str = "hello world";

        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < str.length(); i++) {
            char key = str.charAt(i);
            map.compute(key, (k, v) -> {
                if (Objects.isNull(v)) {
                    v = 1;
                } else {
                    v += 1;
                }
                return v;
            });
        }
        System.out.println(map);

        Map<Character, Integer> charCountMap1 = str.chars()
                .mapToObj(c -> (char) c)
                .collect(Collectors.toMap(c -> c, c -> 1, Integer::sum));
        System.out.println(charCountMap1);
        charCountMap1.forEach((c, count) -> System.out.println(c + ": " + count));


        Map<Character, Integer> charCountMap2 = str.chars()
                .mapToObj(c -> (char) c)
                .collect(Collectors.groupingBy(c -> c, Collectors.summingInt(c -> 1)));
        System.out.println(charCountMap2);
        charCountMap2.forEach((c, count) -> System.out.println(c + ": " + count));
    }
}




